classdef OccupancyEvent < handle
	%
	%
	% ---------------------------------------------------------------------
	properties
		%
		bPrintDebugInformation;
		iLabel;
		%
		% this is the matrix of the data corresponding to the current event
		aafRawData;
		%
		% these fields instead summarize the various transitions times
		aaiDoorOpeningClosingTransitions;
		aaiLaser1OpeningClosingTransitions;
		aaiLaser2OpeningClosingTransitions;
		%
		% this info contains the type of event
		strMeasuredClass;
		%
		% this is instead the resulting variation of number of people
		iResultingMeasuredClass;
		%
		% this is the estimated class only be assigned when it is incorrect
		% classified.
		strEstimatedClass;
		%
		% this is instead the resulting variation of number of people
		iResultingEstimatedClass;
		%
		% this is the features
		afFeatures;
		%		
		% this instead is the julian date corresponding to the beginning
		% and ending of the event
		fStartingJulianDate;
		fEndingJulianDate;
		%
		% flag to understand if it is a meaningful event
		bIsValid;
		%
	end %
	%
	%
	% ---------------------------------------------------------------------
	methods
		%
		% standard constructor
		function tEvent = OccupancyEvent( aafRawData )
		if( nargin > 0 )
			%
			tParameters = PeopleCounters.LoadParameters();
			%
			tEvent.bPrintDebugInformation = false;
			%
			% save the raw data
			tEvent.aafRawData		= aafRawData;
			%
			% compute the labels
			if( numel( aafRawData ) > 0 )
				%
				tEvent.iLabel					= aafRawData(1, 2);
				tEvent.fStartingJulianDate		= aafRawData(1, 3);
				tEvent.fEndingJulianDate		= aafRawData(end, 3);
				%
			else%
				%
				tEvent.iLabel					= 0;
				tEvent.fStartingJulianDate		= 0;
				tEvent.fEndingJulianDate		= [];
				%
			end;%
			%
			tEvent.strMeasuredClass			= [];
			tEvent.strEstimatedClass		= [];
			tEvent.iResultingMeasuredClass	= [];
			tEvent.iResultingEstimatedClass	= [];
			%
			[	tEvent.aaiDoorOpeningClosingTransitions,				...
				tEvent.aaiLaser1OpeningClosingTransitions,				...
				tEvent.aaiLaser2OpeningClosingTransitions	] =			...
					PeopleCounters.FindOpeningClosingTransitions( tEvent.aafRawData );
			%
			tEvent.ComputeValidity();
			%
			if( tEvent.bIsValid )
				%
				% merge also the 'too near' dooropen->doorclose transitions. These will correspond
				% to single occupancy events
				tEvent.aaiDoorOpeningClosingTransitions = 												...
					PeopleCounters.MergeTooCloseTransitions( tEvent.aaiDoorOpeningClosingTransitions,		...
														tParameters.iThresholdForDoorEventsMerging		);
				tEvent.aaiLaser1OpeningClosingTransitions = 											...
					PeopleCounters.MergeTooCloseTransitions( tEvent.aaiLaser1OpeningClosingTransitions,		...
														tParameters.iThresholdForLaser1EventsMerging	);
				tEvent.aaiLaser2OpeningClosingTransitions = 											...
					PeopleCounters.MergeTooCloseTransitions( tEvent.aaiLaser2OpeningClosingTransitions,		...
														tParameters.iThresholdForLaser1EventsMerging	);
				%
				tEvent.ComputeFeatures();
				%
				if( tEvent.bPrintDebugInformation )
					%
% 					tEvent.Print();
					tEvent.Plot();
					%
				end;%
				%
			else%
				%
% 				fprintf('discarded event %d\n', tEvent.iLabel);
				%
			end;% if the event is invalid
		    %
		end;% construction of arrays of objects
		end % standard constructor
		%
	end %
	%
	%
	%
	% ---------------------------------------------------------------------
	methods(Static = true)
		%
		%
	end	%
	%
	%
end %
